package builders;

import java.util.ArrayList;
import java.util.List;

import org.joda.time.DateTime;

import books.Author;
import books.BookInfo;
import books.Category;
import books.Publisher;

/**
 */
public class BookInfoBuilder implements IBuilderExampler<BookInfo> {

    private String isbn;

    private String description;

    private DateTime registrationDate;

    private Publisher publisher;

    private List<Author> authors;

    private List<Category> categories;

    private boolean available;

    private String title;

    public BookInfoBuilder() {
        this.isbn = "";
        this.description = "";
        this.registrationDate = DateTime.now();
        this.available = true;
        this.authors = new ArrayList<Author>();
        this.categories = new ArrayList<Category>();
        this.title = "";
    }

    @Override
    public BookInfo build() {
        return new BookInfo(this);
    }

    public BookInfoBuilder withTitle(final String aTitle) {
        this.title = aTitle;
        return this;
    }

    public BookInfoBuilder withIsbn(final String anIsbn) {
        this.isbn = anIsbn;
        return this;
    }

    public BookInfoBuilder andAuthor(final Author anAuthor) {
        this.getAuthors().add(anAuthor);
        return this;
    }

    public BookInfoBuilder withAuthor(final Author anAuthor) {
        this.getAuthors().add(anAuthor);
        return this;
    }

    public BookInfoBuilder andCategory(final Category aCategory) {
        this.getCategories().add(aCategory);
        return this;
    }

    public BookInfoBuilder withCategory(final Category aCategory) {
        this.getCategories().add(aCategory);
        return this;
    }

    public BookInfoBuilder withAvailability(final Boolean bool) {
        this.available = bool;
        return this;
    }

    public BookInfoBuilder withRegistration(final DateTime aDate) {
        this.registrationDate = aDate;
        return this;
    }

    public BookInfoBuilder withDescription(final String aDescription) {
        this.description = aDescription;
        return this;
    }

    public BookInfoBuilder withPublisher(final Publisher aPublisher) {
        this.publisher = aPublisher;
        return this;
    }

    public BookInfoBuilder withAuthors(final List<Author> anAuthors) {
        this.authors = anAuthors;
        return this;
    }

    public BookInfoBuilder withCategories(final List<Category> aCategories) {
        this.categories = aCategories;
        return this;
    }

    public String getTitle() {
        return this.title;
    }

    public void setTitle(final String title) {
        this.title = title;
    }

    public String getIsbn() {
        return this.isbn;
    }

    public void setIsbn(final String isbn) {
        this.isbn = isbn;
    }

    public String getDescription() {
        return this.description;
    }

    public void setDescription(final String description) {
        this.description = description;
    }

    public DateTime getRegistrationDate() {
        return this.registrationDate;
    }

    public void setRegistrationDate(final DateTime registrationDate) {
        this.registrationDate = registrationDate;
    }

    public Publisher getPublisher() {
        return this.publisher;
    }

    public void setPublisher(final Publisher publisher) {
        this.publisher = publisher;
    }

    public List<Author> getAuthors() {
        return this.authors;
    }

    public void setAuthors(final List<Author> authors) {
        this.authors = authors;
    }

    public List<Category> getCategories() {
        return this.categories;
    }

    public void setCategories(final List<Category> categories) {
        this.categories = categories;
    }

    public boolean isAvailable() {
        return this.available;
    }

    public void setAvailable(final boolean available) {
        this.available = available;
    }

    @Override
    public BookInfo example() {
        return new BookInfoBuilder().withDescription("description").withAvailability(true).withIsbn("1111111111111")
                .withPublisher(new PublisherBuilder().example()).andAuthor(new AuthorBuilder().example())
                .withTitle("title").withRegistration(DateTime.now()).withAuthor(new AuthorBuilder().example())
                .withCategory(Category.GAMES).withCategory(Category.CLASSICS).build();
    }
}
